package com.scau.yangsuiyu.estore.controller.seller;

import com.alibaba.fastjson.JSONObject;
import com.scau.yangsuiyu.estore.controller.MainStageController;
import com.scau.yangsuiyu.estore.controller.myComponent.TopSpan;
import com.scau.yangsuiyu.estore.controller.seller.manageBasicInfo.ManageSellerInfo;
import com.scau.yangsuiyu.estore.controller.seller.manageOrder.ManageSellerOrder;
import com.scau.yangsuiyu.estore.controller.seller.manageShop.ManageSellerShop;
import com.scau.yangsuiyu.estore.dababases.dao.OrderDao;
import com.scau.yangsuiyu.estore.dababases.entity.Buyer;
import com.scau.yangsuiyu.estore.dababases.entity.Seller;
import de.felixroske.jfxsupport.FXMLController;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Tab;
import javafx.scene.layout.AnchorPane;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author suiyu_yang
 * @description
 * @date 2019-05-31 19:52
 * @email suiyu_yang@163.com
 */
//@FXMLController
public class SellerLayoutController extends AnchorPane implements Initializable {
    private MainStageController mainStageController;
    private Seller seller;

    private TopSpan topSpan;

    @FXML
    private AnchorPane topSpanContainer;
    @FXML
    private Tab sellerDetailTab;

    @FXML
    private Tab manageShopTab;

    @FXML
    private Tab manageOrdersTab;


    public SellerLayoutController(JSONObject sellerJson) {
        this.mainStageController = sellerJson.getObject("MainStageController", MainStageController.class);
        this.seller = sellerJson.getObject("user", Seller.class);
        this.topSpan = new TopSpan(seller);
        loadFXML();
    }


    private void loadFXML() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/seller/SellerLayout.fxml"));
        fxmlLoader.setController(this);
        fxmlLoader.setRoot(this);
        try {
            fxmlLoader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        ManageSellerInfo manageSellerInfo = new ManageSellerInfo(seller);
        sellerDetailTab.setContent(manageSellerInfo);

        ManageSellerShop manageSellerShop = new ManageSellerShop(seller);
        manageShopTab.setContent(manageSellerShop);

        ManageSellerOrder manageSellerOrder = new ManageSellerOrder(seller);
        manageOrdersTab.setContent(manageSellerOrder);

        topSpanContainer.getChildren().add(topSpan);
    }

}
